package tech.aistar.day10;

import java.util.TreeSet;

/**
 * 本类用来演示:底层是红黑树
 *
 * @author: success
 * @date: 2021/3/22 1:59 下午
 */
public class TreeSetDemo {
    public static void main(String[] args) {
        TreeSet<Book> books = new TreeSet<>();
        Book b1 = new Book(1,"1001","西游记",100.0d);
        Book b2 = new Book(3,"1003","西游记3",300.0d);
        Book b3 = new Book(2,"1002","西游记2",100.0d);
        Book b4 = new Book(4,"1004","西游记4",200.0d);

        //id - 一般是根据

        //能够添加到TreeSet容器中的数据,一定必须要实现了java.lang.Comparable接口
        //满足的数据 - 这些对象不能是重复的 - 排序规则是根据comparaTo自然排序中指定的规则
        //如果price一样,只会保留1个.
        books.add(b1);
        books.add(b2);
        books.add(b3);
        books.add(b4);

        for (Book book : books) {
            System.out.println(book);
        }
    }
}
